package xworker.function;

import xworker.lang.util.FileUtils;

import java.io.*;

public class ChangeLangToFunction {

    public static void change(File file) throws IOException {
        if(file.isFile()){
            FileInputStream fin = new FileInputStream(file);
            BufferedReader br = new BufferedReader(new InputStreamReader(fin));
            String line = null;
            StringBuilder sb = new StringBuilder();
            boolean changed = false;
            while((line = br.readLine()) != null){
                if(line.startsWith("@xworker.ui")){
                    System.out.println(line);
                    line = "@xworker.function.ui" + line.substring(11);
                    System.out.println("    " + line);
                    sb.append(line).append("\n");
                    changed = true;
                }else{
                    sb.append(line).append("\n");
                }

            }
            fin.close();

            if(changed){
                FileOutputStream fout = new FileOutputStream(file);
                fout.write(sb.toString().getBytes());
                fout.close();
            }
        }else{
            for(File child : FileUtils.listFiles(file)){
                change(child);
            }
        }
    }
    public static void main(String[] args){
        try{
            change(new File("./xworker_function/src/main/resources"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
